package com.csi.config;

import com.csi.controller.inteceptor.FullInterceptor;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Configuration
@EnableWebMvc
@EnableScheduling
//@EnableCaching
@ComponentScan("com.csi.controller")
public class SpringMVCConfig implements WebMvcConfigurer {
    @Bean
    public StandardServletMultipartResolver multipartResolver(){
        return new StandardServletMultipartResolver();
    }

    @Bean
    public HandlerMapping handlerMapping() {
        return new RequestMappingHandlerMapping() ;
    }

    @Bean
    public HandlerAdapter handlerAdapter() {
        return new RequestMappingHandlerAdapter() ;
    }


//    @Autowired
//    private PermissionInterceptor permissionInterceptor;
    //添加拦截器
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
        //将拦截器添加到Springmvc环境,默认拦截所有Springmvc分发的请求
        /*registry.addInterceptor(new FullInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/employee/login");*/

//        registry.addInterceptor(permissionInterceptor)
//                .addPathPatterns("/user/*")
//                .addPathPatterns("/bill/*")
//                .addPathPatterns("/provider/*")
//                .excludePathPatterns("/user/login");
//    }

    /**
     * 跨域请求 全局配置
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry
                .addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("*")
                .allowedHeaders("*");
    }



    //配置静态资源
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }



}
